﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CDO;
namespace Dimok.Web.Utils {

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>	Mime converter. </summary>
	///
	/// <remarks>	Dimon, 12/21/2010. </remarks>
	////////////////////////////////////////////////////////////////////////////////////////////////////

	public class MIMEConverter {
		//private ctor as our methods are all static here

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Default constructor. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private MIMEConverter() {

		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Saves a web page to mht file. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="url">			URL of the document. </param>
		/// <param name="filePath">	Full pathname of the file. </param>
		///
		/// <returns>	true if it succeeds, false if it fails. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static bool SaveWebPageToMHTFile(string url, string filePath) {
            throw new NotImplementedException();
            //bool result = false;
            //CDO.Message msg = new CDO.MessageClass();
            //try {
            //    msg.MimeFormatted = true;
            //    msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
            //    var stm = msg.GetStream();
            //    stm.SaveToFile(filePath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
            //    msg = null;
            //    stm.Close();
            //    result = true;
            //} catch { throw; } finally {
            //    //cleanup here  
            //}
            //return result;
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Convert web page to mht string. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="url">	URL of the document. </param>
		///
		/// <returns>	. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static string ConvertWebPageToMHTString(string url) {
			return ConvertWebPageToMHTString(url, "", "");
		}

		////////////////////////////////////////////////////////////////////////////////////////////////////
		/// <summary>	Convert web page to mht string. </summary>
		///
		/// <remarks>	Dimon, 12/21/2010. </remarks>
		///
		/// <param name="url">			URL of the document. </param>
		/// <param name="userName">	Name of the user. </param>
		/// <param name="password">	The password. </param>
		///
		/// <returns>	. </returns>
		////////////////////////////////////////////////////////////////////////////////////////////////////

		public static string ConvertWebPageToMHTString(string url,string userName,string password) {
            throw new NotImplementedException();
            //string data = String.Empty;
            //CDO.Message msg = new CDO.MessageClass();
            //try {
            //    msg.MimeFormatted = true;
            //    msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, userName, password);
            //    var stm = msg.GetStream();
            //    data = stm.ReadText(stm.Size);
            //} catch {
            //    throw;
            //} finally {
            //    //cleanup here
            //}
            //return data;
		}
	}
}
